package com.jang.service.cases;

import com.jang.Entity.ResponseEntity;
import com.jang.Entity.cases.CaseRuningEntity;
import com.jang.Entity.cases.ConfigEntity;
import com.jang.Entity.cases.DictEntity;
import com.jang.mapper.cases.ConfigMapper;
import com.jang.utils.ResultHandle;
import org.apache.ibatis.annotations.Case;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class ConfigServiceImpl implements ConfigService {
    @Autowired
    ConfigMapper configMapper;

    /**
     * 请求头配置
     **/
    @Override
    public Object getHerderConfig(){
        List<ConfigEntity> list = configMapper.getHeaderConfig();
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }
    @Override
    public Object updateHerderConfig(ConfigEntity configEntity){
        int result = configMapper.updateHeaderConfig(configEntity);
        return ResultHandle.returnWeb(result);
    }
    @Override
    public Object insertHerderConfig(ConfigEntity configEntity){
        int result = configMapper.insertHeaderConfig(configEntity);
        return ResultHandle.returnWeb(result);
    }
    /**
     * 环境配置
     **/
    @Override
    public Object getEnvConfig(){
        List<ConfigEntity> list = configMapper.getEnvConfig();
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }
    @Override
    public Object getEnvConfigById(int env_id){
        ConfigEntity configEntity = configMapper.getEnvConfigById(String.valueOf(env_id));
        List list =new ArrayList();
        list.add(configEntity);
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }

    @Override
    public Object updateEnvConfig(ConfigEntity configEntity){
        int result = configMapper.updateEnvConfig(configEntity);
        return ResultHandle.returnWeb(result);
    }
    @Override
    public Object DelEnvConfig(ConfigEntity configEntity){
        if (configEntity.getDelete_flag()==1){
            configEntity.setDelete_flag(0);
        }else {
            configEntity.setDelete_flag(1);
        }
        int result = configMapper.DelEnvConfig(configEntity);
        return ResultHandle.returnWeb(result);
    }
    @Override
    public Object insertEnvConfig(ConfigEntity configEntity){
        ResponseEntity responseEntity = new ResponseEntity();
        int result = configMapper.insertEnvConfig(configEntity);
        return ResultHandle.returnWeb(result);
    }
    @Override
    public Object getDict(String key){
        List<DictEntity> list = configMapper.getDict(key);
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }
    /********测试计划*****/
    @Override
    public Object getTestPlan(){
        List<CaseRuningEntity> list = configMapper.getTest_plan();
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }
    @Override
    public Object getTestPlanById(int plan_id){
        CaseRuningEntity caseRuningEntity = configMapper.getTest_planById(String.valueOf(plan_id));
        List list =new ArrayList();
        list.add(caseRuningEntity);
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }
    @Override
    public Object updateTestPlan(CaseRuningEntity caseRuningEntity){
        int result = configMapper.updateTestPlan(caseRuningEntity);
        List list =new ArrayList();
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }
    @Override
    public Object DelTestPlan(CaseRuningEntity caseRuningEntity){
        System.out.println("sss : "+caseRuningEntity.getDelete_flag());
//        if (caseRuningEntity.getDelete_flag()==1){
//            caseRuningEntity.setDelete_flag(0);
//            System.out.println("sdsd : "+caseRuningEntity.getDelete_flag());
//        }else {
//            caseRuningEntity.setDelete_flag(1);
//        }
        int result = configMapper.DelTestPlan(caseRuningEntity);
        return ResultHandle.returnWeb(result);
    }
    @Override
    public Object inserTestPlan(CaseRuningEntity caseRuningEntity){
        ResponseEntity responseEntity = new ResponseEntity();
        int result = configMapper.insertTestPlan(caseRuningEntity);
        return ResultHandle.returnWeb(result);
    }

    @Override
    public Object getProject(){
        List<CaseRuningEntity> list = configMapper.getProject();
        ResponseEntity responseEntity = ResultHandle.returnWeb(1);
        responseEntity.setData(list);
        return responseEntity;
    }
}
